<template>
  <el-dialog
    title="修改报告信息"
    :visible.sync="dialogEditorVisible"
    width="30%"
    :before-close="handleClose">
   
<el-form  class="demo-form-inline"  ref="form" :model="currentRow"  label-width="100px">
<el-form-item label="报告编号">
        <el-input v-model="currentRow.reportNo"></el-input>
      </el-form-item>
      <el-form-item label="报告类型">
        <el-select style="width:100%" v-model="currentRow.reportType" placeholder="请选择报告类型">
            <el-option label="周报"  value="1"></el-option>
            <el-option label="月报"  value="2"></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="报告时间">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-model="currentRow.createTime"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="报告附件">
        <el-upload
          name="file"
          class="upload-demo"
          action="string"
          :http-request="beforeAvatarUploadThree"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :before-remove="beforeRemove"
          multiple
          :limit="3"
          :on-success="handlesuccess"
          :on-error="handleerror"
          :on-exceed="handleExceed"
          :file-list="fileList"
        >
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
      </el-form-item>


</el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogEditorVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>

import api from "../../../api";
import qs from "qs"

export default {
  data(){
    return {
      tId:'',
      dialogEditorVisible: false,
      tunnelList:[],
      fileList: [] ,
      currentRow: {},
      fileList:[]
    }
  },
   props: {
    flag: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
     this.$bus.$on("onShowTunnelDirectionEditor", (row) => {
       this.dialogEditorVisible = true;
       this.currentRow = row.rowdata
       this.tId = row.tId
     })
  },
  methods: {
      handleClose(done) {
              this.$confirm('确认关闭？')
                .then(_ => {
                 
                  done();
                }).catch(_ => {});
      },
      create(){
        api.monitorReportupdate(qs.stringify(this.currentRow)).then(res=>{
          if (res.data.code == 2001){
                this.$message({
                  type: 'success',
                  message: '更新成功!'
                });
                this.dialogEditorVisible = false
               this.$bus.$emit("onRefreshMonitorReport",this.tId)
          }else{
            this.$message({
                  type: 'fail',
                  message: '更新失败!'
                });
               this.dialogVisible = false
               this.$bus.$emit("onRefresh",true)
          }

        }).catch(err=>{
        })
      },
      onSubmit() {
        console.log('submit!');
      },
     // 上传图片前的过滤
     beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 1000
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 200MB!')
      }
      return isLt2M
    },
    handlePreview(file) {
      console.log(file)
    },
    handlesuccess(response, file, fileList) {
      console.log(response)
      if (response.code == 2001) {
        this.MonitorReport.resources = response.data
      }
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
      )
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleerror(err, file, fileList) {
      console.log(err)
    },
    beforeAvatarUploadThree(file) {
      let params = new FormData()
      params.append('file', file.file)
      api
        .AddrPlaneFileUpload(params)
        .then((res) => {
          if (res.data.code == 2001) {
            this.currentRow.resources = res.data.data
          }
        })
    }
  }

}
</script>

<style scoped>
  .avatar-uploader .el-upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px dashed #d9d9d9;
    border-radius: 6PX;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    width: 50PX !important;
    height: 50PX !important;
    font-size: 28PX;
    line-height: 50PX !important;
    color: #8c939d;
    text-align: center;
  }
  .avatar {
    display: block;
    width: 50PX !important;
    height: 50PX !important;
  }
  .imgbeforepad{
    padding-top: 0px !important;
  }
  .avatar-uploader .el-icon-plus{
    margin: 15PX !important;
  }

</style>